package com.javathread.th1.waitwn;

/**
 * 类说明  快递实体类
 * @author Administrator
 *
 */
public class Express {
	
	public final static String CITY = "WuHan";
	
	private int km;/**快递运输里程数**/
	private String site;/**快递到达地点**/
	
	//构造函数
	public Express() {
		
	}
	
	public Express(int km,String site) {
		this.km = km;
		this.site = site;
	}
	
	/* 变化公里数 然后通知处于wait 状态并需要处理公里数的线程进行业务处理 */
	public synchronized void ChangeKm() {
			this.km = 99;
			this.notifyAll();
			//其他的业务代码
	}
	/* 变化地点 然后通知处于wait 状态并需要处理地点的线程进行业务处理 */
	public synchronized void changeSite() {
		this.site = "WuHan";
		notifyAll();
	}
	
	public synchronized void waitKm() throws InterruptedException {
		while (this.km<=100) {
			wait();
			System.out.println("====check km thread[" + Thread.currentThread().getId() + "] is be notifed");
		}
		System.out.println("当前 km =" + this.km + ",修改数据库数据");
	}
	
	public synchronized void waitSite() throws InterruptedException {
		while (CITY.equals(this.site)) {
			wait();
			System.out.println("=====check site thread[" + Thread.currentThread().getId() + "] is be notifed");
		}
		
		System.out.println("当前站点="+this.site + ",将要通知用户");
	}
	

	public static void main(String[] args) {

	}

}
